package io.mvvm.common.entity;

import io.mvvm.common.enumerate.ResponseEnum;
import lombok.Builder;
import lombok.Data;

/**
 * @program: seize-login
 * @description:
 * @author: 潘
 * @create: 2021-05-14 22:34
 **/
@Data
@Builder
public class AjaxResponse {

    private int code;
    private String msg;
    private Object data;
    private String token;

    public static AjaxResponse success(int code, String msg, Object data, String token) {
        return builder().code(code).msg(msg).data(data).token(token).build();
    }

    public static AjaxResponse success() {
        return builder().code(ResponseEnum.SUCCESS.getCode()).msg(ResponseEnum.SUCCESS.getMessage())
                .data(null).token(null).build();
    }

    public static AjaxResponse success(Object data) {
        return builder().code(ResponseEnum.SUCCESS.getCode()).msg(ResponseEnum.SUCCESS.getMessage())
                .data(data).token(null).build();
    }

    public static AjaxResponse success(ResponseEnum responseEnum, Object data, String token) {
        return builder().code(responseEnum.getCode()).msg(responseEnum.getMessage())
                .data(data).token(token).build();
    }



    public static AjaxResponse error() {
        return builder().code(ResponseEnum.ERROR.getCode()).msg(ResponseEnum.ERROR.getMessage())
                .data(null).token(null).build();
    }
    public static AjaxResponse error(ResponseEnum responseEnum) {
        return builder().code(responseEnum.getCode()).msg(responseEnum.getMessage())
                .data(null).token(null).build();
    }
    public static AjaxResponse error(ResponseEnum responseEnum, Object data) {
        return builder().code(responseEnum.getCode()).msg(responseEnum.getMessage())
                .data(data).token(null).build();
    }
    public static AjaxResponse error(Object data) {
        return builder().code(ResponseEnum.ERROR.getCode()).msg(ResponseEnum.ERROR.getMessage())
                .data(data).token(null).build();
    }

}
